package com.cf.r1020;

import java.io.*;

public class c {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        in.nextToken(); int T = (int) in.nval;
        while (T-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        in.nextToken(); int n = (int) in.nval;
        in.nextToken(); int k = (int) in.nval;
        int[] a = new int[n];
        int[] b = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            in.nextToken(); a[i] = (int) in.nval;
            max = Math.max(max, a[i]);
            min = Math.min(min, a[i]);
        }
        int asert = -1;
        for (int i = 0; i < n; i++) {
            in.nextToken(); b[i] = (int) in.nval;
        }
        for (int i = 0; i < n; i++) {
            if (b[i] != -1) {
                if (asert == -1) {
                    asert = b[i] + a[i];
                } else if (b[i] + a[i] != asert) {
                    out.println(0);
                    return;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (asert != -1 && a[i] > asert) {
                out.println(0);
                return;
            }
        }
        if (asert != -1) {
            for (int i = 0; i < n; i++) {
                if (b[i] == -1) {
                    if (asert - a[i] > k) {
                        out.println(0);
                        return;
                    }
                }
            }
            out.println(1);
        } else {
            out.println(k - (max - min) + 1);
        }
    }
}
